web3.js - Block Gas Limit を取得する
web3.js を使用して、Ethereum の Block Gas Limit を取得する方法です。
web3.eth.getBlock で返されるオブジェクトの gasLimit プロパティの値を参照します。
サンプルコード
code:example.js
web3.eth.getBlock("latest", false, (error, result) => {
console.log(result.gasLimit)
// => 8000029
});
動作デモ
実行
code:demo.js
const web3 = new Web3(Web3.givenProvider || 'wss://mainnet.infura.io/ws')
web3.eth.getBlock("latest", false, (error, result) => {
console.log(result.gasLimit)
$(document.body).append('<h1>The latest Block Gas Limit</h1>')
$(document.body).append('<p><input type="text" size="10" value="' + result.gasLimit + '" readonly> gas</p>')
})
メモ
Block Gas Limit についてのメモは Ethereum の Block Gas Limit を取得 を参照してください。
参考
http://blog.playground.io/entry/2018/05/04/124926
関連
Ethereum の Block Gas Limit を取得
web3.js 逆引きリファレンス #howto